<script setup lang="tsx">
import noPermission from '@/assets/svgs/403.svg'
import pageError from '@/assets/svgs/404.svg'
import networkError from '@/assets/svgs/500.svg'
import { errorCode } from '@/common/constants/errorCode'
import { propTypes } from '@fetm/shared-utils'
import { ElButton } from 'element-plus'

const props = defineProps({
  type: propTypes.string
    .validate((v: string) => ['404', '500', '403'].includes(v))
    .def('404'),
})

const emit = defineEmits(['errorClick'])

const errorMap = {
  404: {
    img: pageError,
    message: errorCode[404],
    buttonText: '返回首页',
  },
  500: {
    img: networkError,
    message: errorCode[500],
    buttonText: '返回首页',
  },
  403: {
    img: noPermission,
    message: errorCode[403],
    buttonText: '返回首页',
  },
}
function btnClick() {
  emit('errorClick', props.type)
}
</script>

<template>
  <div class="flex justify-center">
    <div class="text-center">
      <img width="350" :src="errorMap[type].img">
      <div class="text-14px text-[var(--el-color-info)]">
        {{ errorMap[type].message }}
      </div>
      <div class="mt-20px">
        <ElButton type="primary" @click="btnClick">
          {{ errorMap[type].buttonText }}
        </ElButton>
      </div>
    </div>
  </div>
</template>
